package com.example.dao;

import com.example.domain.PostLike;
import org.apache.ibatis.annotations.*;

public interface PostLikeMapper {

    // 添加点赞
    @Insert("INSERT INTO post_like (user_id, post_id, create_time) VALUES (#{userId}, #{postId}, #{createTime})")
    void addLike(PostLike postLike);

    // 取消点赞
    @Delete("DELETE FROM post_like WHERE user_id = #{userId} AND post_id = #{postId}")
    void removeLike(@Param("userId") Integer userId, @Param("postId") Integer postId);

    // 检查用户是否已点赞
    @Select("SELECT COUNT(*) FROM post_like WHERE user_id = #{userId} AND post_id = #{postId}")
    int isLiked(@Param("userId") Integer userId, @Param("postId") Integer postId);

    // 获取帖子点赞数
    @Select("SELECT COUNT(*) FROM post_like WHERE post_id = #{postId}")
    int getLikeCount(@Param("postId") Integer postId);

    // 获取用户点赞的帖子列表
    @Select("SELECT post_id FROM post_like WHERE user_id = #{userId}")
    java.util.List<Integer> getUserLikedPosts(@Param("userId") Integer userId);
}
